package org.example.stream;

import org.example.entity.Fruit;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

public class Stream01 {
    public static void main(String[] args) {
        // 注意：这里of方法接受的是多个对象，用的不是集合，和我们手写的不太一样
        Stream.of(
                        new Fruit("草莓", "Strawberry", "浆果", "红色"),
                        new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                        new Fruit("杨梅", "Wax-berry", "浆果", "红色"),
                        new Fruit("核桃", "Walnut", "坚果", "棕色"),
                        new Fruit("花生", "Peanut", "坚果", "棕色"),
                        new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")
                // 注意：这里的条件可以写多个
                ).filter(fruit -> "浆果".equals(fruit.getCategory()) && "蓝色".equals(fruit.getColor()))
                .map(fruit -> fruit.getCname()+"酱")
                .forEach(System.out::println);


        Stream.of(
                Arrays.asList(
                        new Fruit("草莓", "Strawberry", "浆果", "红色"),
                        new Fruit("桑葚", "Mulberry", "浆果", "紫色"),
                        new Fruit("杨梅", "Wax-berry", "浆果", "红色"),
                        new Fruit("核桃", "Walnut", "坚果", "棕色")
                ),
                Arrays.asList(
                        new Fruit("花生", "Peanut", "坚果", "棕色"),
                        new Fruit("蓝莓", "Blueberry", "浆果", "蓝色")                        )// 注意：这里的条件可以写多个
        )
                // 这里的扁平化  入参是list 响应是stream
                .flatMap(Collection::stream).forEach(System.out::println);


        Integer[][] array2D = {
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };
        Arrays.stream(array2D).flatMap(Arrays::stream).forEach(System.out::println);
    }
}
